<template>
  <el-row type="flex" justify="space-between" style="width:100%;height:40px;" align="middle">
    <!-- 左边 -->
    <el-col>
      <span>{{treeData.name}}</span>
    </el-col>
    <!-- 右边 -->
    <el-col :span="10">
      <el-row type="flex" justify="end">
        <el-col>{{treeData.manager}}</el-col>
        <el-col>
          <!-- 下拉框 -->
          <el-dropdown>
            <span class="el-dropdown-link">
              操作<i class="el-icon-arrow-down el-icon--right"></i>
            </span>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item @click.native="$emit('openDialog',treeData.id)">添加子部门</el-dropdown-item>
              <el-dropdown-item v-if="!isRoot" @click.native="$emit('editDialog',treeData.id)">编辑部门</el-dropdown-item>
              <el-dropdown-item v-if="!isRoot" @click.native="delDepart">删除部门</el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
          <!-- el-dropdown-item 组件并未对click事件进行包装处理。需要添加native修饰符 -->
        </el-col>
      </el-row>
    </el-col>
  </el-row>
</template>
<script>
import { delDepartmentApi } from '@/api/department'
export default {
  name: 'TreeTools',
  props: {
    // 这一行的数据
    treeData: {
      type: Object,
      default: () => ({})
    },
    // 是否顶级
    isRoot: {
      type: Boolean,
      default: false
    }
  },
  methods: {
    // 删除部门
    async delDepart() {
      try {
        // 弹出确认框
        await this.$confirm('确认删除吗？')
        // 发生删除请求
        await delDepartmentApi(this.treeData.id)
        // 提示成功
        this.$message.success('删除成功')
        // 删除成功列表更新
        this.$emit('updateList')
      } catch (error) {
        console.log(error);
      }

    }
  },
}
</script>

<style>
</style>